<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return['ntime']=TIMESTAMP;
if($_RQ['op']=='main'){
        $armg = array('uniacid'=>$_SESSION['uniacid'],'bcount >'=>0);
        // 读取全部在拍和即将开拍的专场，专场内拍品数不能为0
        $pid = $_RQ['pid'];
		$status = intval($_RQ['status']) ? intval($_RQ['status']) : 0;
		/** 筛选条件 **/
		$pindex = max(1, intval($_RQ['page']));
		$psize = 12;
		$total='';
		if($pid){
			$params=array(
				'uniacid'=>$_SESSION['uniacid'],
				'bcount >'=>0,
				'cid'=>$pid,
				'hide'=>0,
			);
		}else{
			$params=array('uniacid'=>$_SESSION['uniacid'],'bcount >'=>0);
		}
		if ($status == 1) {
				$params['starttime <']=TIMESTAMP;
				$params['endtime >']=TIMESTAMP;
			} elseif ($status == 3) {
				$params['starttime >']=TIMESTAMP;
			} elseif ($status == 2){
				$params['endtime <']=TIMESTAMP;
		}
		
		$splist=pdo_getslice('jy_jdpm_special_auction',$params,array($pindex,$psize),$total,array(),'','endtime desc');
		if($splist){
				foreach ($splist as $key => &$value) {
					$value['goods']=pdo_getall('jy_jdpm_auction',array('id'=>$value['id']),'','','endtime desc');
					foreach ($value['goods'] as $key => &$g) {
						$goodsinfo = get_goodsinfo($g['goodsid']);
						$g['image'] = $goodsinfo['image'];
						$g['status'] = $g['starttime'] > time() ? 0 : ($g['endtime'] > time() ? 1 : 2);
					}
					$value['status'] = $value['starttime'] > time() ? 0 : ($value['endtime'] > time() ? 1 : 2);
					$value['images'] = explode('|' , $g['images'])[0];
					$value['bidding']=$value['mid']>0 ?($value['nowprice']+($value['onset']/10)):$value['onset'];
					$value['clinch']=$value['mid']>0?$value['nowprice']:$value['onset'];
					$value['bzprice']=$value['mid']>0?(($value['nowprice'] +($value['onset']/10))>=($value['onset']*3)?($value['nowprice']+($value['onset']/10)):($value['nowprice']+($value['onset']/10))/2):$value['onset']/2;
					$value['ingname']=substr($value['mid'] ,0, 1) . '******' . substr($value['mid'] , -1);
					$value['endtime2'] = date('Y/m/d H:i:s',$value['endtime']);
					$value['starttime2'] = date('Y/m/d H:i:s',$value['starttime']);
				}
		}
		$return['splist']=$splist?$splist:array();
		$totalpage=ceil($total/$psize);
		$totalpage=intval($totalpage);
		$return['totalpage'] =$totalpage;
		$return['params']['page'] =$pindex;
		$return['count'] = $count;
        $return['list'] = $list;
        // 为了页面美观，仅获取专场与显示专场数量相同的热拍商品
	$return['channel'] = pdo_getall('jy_jdpm_goods_group',array('pid' => 0),'','','paixu asc');
     $return['limit'] = count($list);
	 $d=date();
     $return['nowTime'] = date("Y-m-d h:i:sa", $d);;
	set_html('title','专场-'.$this->plugin_setting('basic')['title']);
	$return['sharedata'] =array(
			'title'=>'专场-'.$this->plugin_setting('basic')['title'],
			'desc'=>'专场-'.$this->plugin_setting('basic')['title'],
			'link'=>custom_url('jy_jdpm/special.index/'),
			'imgUrl'=>$_SESSION['account']['logo'] ? $_AR['siteroot'].'resource/'.$_SESSION['account']['logo'] : $_AR['siteroot'].'core/resource/images/nopic.jpg',
	);
	$return['extradata']=array();
	exi($return);
}
if($_RQ['op']=='getlist'){
	$cid = intval($_RQ['cid']);
	$status = intval($_RQ['status']);
	/** 筛选条件 **/
	$pindex = max(1, intval($_RQ['page']));
	$psize = 12;
	$total='';
	$params=array('uniacid'=>$_SESSION['uniacid'],'bcount >'=>0);
	if($cid){
			$params['cid']=$cid;
			$params['hide']=0;
	}
	if ($status == 1) {
            $params['starttime <']=TIMESTAMP;
			$params['endtime >']=TIMESTAMP;
    } elseif ($status == 3) {
            $params['starttime >']=TIMESTAMP;
    } elseif ($status == 2){
            $params['endtime <']=TIMESTAMP;
    }
	
	$splist=pdo_getslice('jy_jdpm_special_auction',$params,array($pindex,$psize),$total,array(),'','endtime desc');
	if($splist){
			foreach ($splist as $key => &$value) {
				$value['goods']=pdo_getall('jy_jdpm_auction',array('sid'=>$value['id']),'','','endtime desc');
				foreach ($value['goods'] as $key => &$g) {
					$goodsinfo = get_goodsinfo($g['goodsid']);
					$g['image'] = $goodsinfo['image'];
					$g['status'] = $g['starttime'] > time() ? 0 : ($g['endtime'] > time() ? 1 : 2);
				}
				$value['status'] = $value['starttime'] > time() ? 0 : ($value['endtime'] > time() ? 1 : 2);
				$value['images'] = explode('|' , $g['images'])[0];
				$value['bidding']=$value['mid']>0 ?($value['nowprice']+($value['onset']/10)):$value['onset'];
				$value['clinch']=$value['mid']>0?$value['nowprice']:$value['onset'];
				$value['bzprice']=$value['mid']>0?(($value['nowprice'] +($value['onset']/10))>=($value['onset']*3)?($value['nowprice']+($value['onset']/10)):($value['nowprice']+($value['onset']/10))/2):$value['onset']/2;
				$value['ingname']=substr($value['mid'] ,0, 1) . '******' . substr($value['mid'] , -1);
				$value['endtime2'] = date('Y/m/d H:i:s',$value['endtime']);
				$value['starttime2'] = date('Y/m/d H:i:s',$value['starttime']);
				$value['scount']=pdo_getsum('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'sid'=>$value['id']),'bidcount');
			}
	}
    $return['splist']=$splist?$splist:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	exi($return);
}
?>